package cn.itsource.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.itsource.service.IPayService;
import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.UserApi;
import com.getui.push.v2.sdk.common.ApiResult;
import com.getui.push.v2.sdk.dto.req.CidAliasListDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 📖：beishan
 * 🗓️：2024/4/21 17:13
 * =====================
 */
@Service
@Transactional
@Slf4j
public class PayServiceImpl implements IPayService {

    /**
     * 创建别名
     * @param cid
     */
    @Override
    public void geTuiAlias(String cid) {
        //填写应用配置
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        apiConfiguration.setAppId("GJOmMrKCojAR5FA3B2GUT2");
        apiConfiguration.setAppKey("4l7tEYkASn68I7xH4Qtno1");
        apiConfiguration.setMasterSecret("hdMVWTPlyP92aVISP4lTA3");
        // 接口调用前缀，请查看文档: 接口调用规范 -> 接口前缀
        apiConfiguration.setDomain("https://restapi.getui.com/v2/");
        // 实例化ApiHelper对象，用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        // 创建对象，建议复用。目前有PushApi、StatisticApi、UserApi
//        PushApi pushApi = apiHelper.creatApi(PushApi.class);

        UserApi userApi = apiHelper.creatApi(UserApi.class);
        CidAliasListDTO cidAliasListDTO = new CidAliasListDTO();
        CidAliasListDTO.CidAlias cidAlias = new CidAliasListDTO.CidAlias(cid, StpUtil.getLoginIdAsString());

        cidAliasListDTO.add(cidAlias);
        log.info("别名 {}",cidAlias);

        ApiResult<Void> voidApiResult = userApi.bindAlias(cidAliasListDTO);
        log.info("绑定结果 {}",voidApiResult);

    }
}
